home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Opening STDOUT As BINARY
- Date: Fri, 05 Apr 96 15:13:54 GMT
- Organization: none
- Message-ID: <828717234snz@genesis.demon.co.uk>
- References: <3161CAD8.296C@netrover.com> <4k1hoe$hn0@sun001.spd.dsccc.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4k1hoe$hn0@sun001.spd.dsccc.com>
- jmccarty@sun1307.spd.dsccc.com "Mike McCarty" writes:
-
- >In article <3161CAD8.296C@netrover.com>,
- >Stephane Charette <charrick@netrover.com> wrote:
- >)I've come across a problem, and I believe that it is
- >)caused by limitations in C/C++. Can anyone help on the
- >)following:
- >)
- >)I need to output binary information to the console, which
- >)is then redirected to a file by the o/s. At the moment,
- >)I'm using printf( "%c", mychar ) to output the the binary
- >)data one character at a time as it comes in.
-
- You could have simply written putchar(mychar)
-
- >)However, it seems that the character #7 (0x07, bell) gets
- >)sent to stdout followed by an automatic CR (0x0A). Every
- >)other character in the ASCII table works fine! Is there
- >)a way to reopen stdout in binary mode instead of as a text
- >)stream? The extra 0x0A characters are corrupting the data!
-
- You could use something like:
-
- freopen(filename, "wb", stdout)
-
- but you need a filename that corresponds to a suitable device. That
- is implementation specific, if it exists at all. For DOS that might be "CON".
- The disadvantage to this is that it will cancel any redirection of stdout
- that might have been performed when your program was run.
-
- >)I've also tried "cout" and "putc", but they yield the same
- >)result.
- >)
- >)Why do I need this: this application runs as a CGI-BIN,
- >)and the web server EXPECTS the output to be sent to
- >)stdout. I cannot fwrite() this information to a physical
- >)file since the web server is capturing the console output!
-
- It might work in this case.
-
- >The behavior you describe has -nothing- to do with C.
-
- It is the C language that defines that stdin, stdout and stderr are
- opened in text rather than binary mode.
-
- >It has to do with
- >the peculiarities of the operating system you are using. Is htis DOS? If
- >so, then investigate putting stdout in binary mode. Your compiler should
- >have a way to do this. Look into variables such as _fmode, __mode etc.
-
- That is probably a good way to go in this case.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-